﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using DocumentFormat.OpenXml.Wordprocessing;

using ProjectBase.Core;

namespace $safeprojectname$.Export.Word
{
    public abstract class DocPartHandlerBase : IDocPartHandler, IPublishingReporter
    {
        public void SetSuccessor(IDocPartHandler successor)
        {
            Successor = successor;
        }

        // IDocPartHandler
        public HandlerResult Handle(DocPart currentPart, IPersistentObject entity, params string[] prefixes)
        {
            // I. can I handle it?
            if (HandleDocPart(currentPart, entity, prefixes).Equals(HandlerResult.Finished))
            {
                return HandlerResult.Finished;
            }

            // II. can my successor handle it?
            if (Successor.Is())
            {
                return Successor.Handle(currentPart, entity, prefixes);
            }
            return HandlerResult.Continue;
        }

        // abstract
        protected abstract HandlerResult HandleDocPart(DocPart currentPart, IPersistentObject entity, params string[] prefixes);

        // successor to pass the handling if needed
        public virtual IDocPartHandler Successor { get; protected set; }

        public virtual int Priority { get { return 100; } }
    }
};